//
//  VideoPlayBackVC.m
//  DanceShow
//
//  Created by cc on 15/11/4.
//  Copyright © 2015年 com.hym. All rights reserved.
//

#import "VideoPlayBackVC.h"
#import "Masonry.h"
@interface VideoPlayBackVC ()
@property(nonatomic,copy)NSURL *videoUrl;
@end

@implementation VideoPlayBackVC

-(instancetype)initWithParams:(NSURL *)videoUrl{
    if(self=[super init]){
        self.videoUrl=videoUrl;
        self.hidesBottomBarWhenPushed=YES;
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];

    [self initView];
}
-(void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    self.navigationController.navigationBar.hidden=YES;
    

}
-(void)viewDidDisappear:(BOOL)animated{
    [super viewDidDisappear:animated];
    self.navigationController.navigationBar.hidden=NO;
     [self.playerView pause];

}
-(void)backButtonClick:(UIButton*)sender{

}
-(BOOL)shouldHideNavigationBar{
    return YES;
}
-(void)initView{

    self.playerView = [[ZFPlayerView alloc] init];
    [self.view insertSubview:self.playerView atIndex:0];
//    self.view.transform=CGAffineTransformMakeRotation(M_PI_2);
    
    UIEdgeInsets padding = UIEdgeInsetsMake(0, 0, 0, 0);
    [self.playerView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.view).with.insets(padding);
    }];
    // Back button event
    __weak typeof(self) weakSelf = self;

    self.playerView.videoURL = self.videoUrl;
    self.playerView.goBackBlock = ^{
            [weakSelf.navigationController popViewControllerAnimated:YES];
    };

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(enterForground) name:@"enterForGround" object:nil];
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(enterBackGround) name:@"enterBackGround" object:nil];
}
-(void)enterForground{
    if(self.navigationController.topViewController==self){
        [self.playerView play];
    }
    return;
}
-(void)enterBackGround{
    [self.playerView pause];
}


-(void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];

}

-(BOOL)prefersStatusBarHidden{
    return YES;
}


@end
